﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using QiAdmin.Core;
using QiAdmin.Core.Attributes;
using QiAdmin.Core.Models;
using QiAdmin.Model.Dtos.Input;
using QiAdmin.Service.IService;
using QiAdmin.Service.Service;

namespace QiAdmin.WebApi.Controllers.System
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SysUserController : ControllerBase
    {
        readonly ITSysUserService _sysUserService;
        readonly ITSysMenuService _sysMenuService;
        public SysUserController(ITSysUserService sysUserService, ITSysMenuService sysMenuService)
        {
            _sysUserService = sysUserService;
            _sysMenuService = sysMenuService;
        }

        [Permission(PermissionType.Query)]
        [HttpPost]
        public ApiJsonResult GetPageList(TSysUser_IN input)
        {
            var res = _sysUserService.GetPageList(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Add)]
        [HttpPost]
        public ApiJsonResult Add(TSysUser_IN input)
        {
            var res = _sysUserService.Add(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Edit)]
        [HttpPost]
        public ApiJsonResult Edit(TSysUser_IN input)
        {
            var res = _sysUserService.Edit(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Query)]
        [HttpPost]
        public ApiJsonResult Get(TSysUser_IN input)
        {
            var res = _sysUserService.Get(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Delete)]
        [HttpPost]
        public ApiJsonResult Remove(TSysUser_IN input)
        {
            var res = _sysUserService.Remove(input);
            return ApiJsonResult.Convert(res);
        }

        [Permission(PermissionType.Delete)]
        [HttpPost]
        public ApiJsonResult RemoveRange(List<TSysUser_IN> input)
        {
            var res = _sysUserService.RemoveRange(input);
            return ApiJsonResult.Convert(res);
        }

        /// <summary>
        /// 获取用户路由、菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiJsonResult GetUserRoute()
        {
            var res = _sysUserService.GetUserTreeMenus();
            return ApiJsonResult.Convert(res);
        }

        /// <summary>
        /// 获取用户的按钮权限
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiJsonResult GetUserBtns()
        {
            var res = _sysUserService.GetUserBtns();
            return ApiJsonResult.Convert(res);
        }


        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <returns></returns>
        [Permission(PermissionType.System)]
        [HttpPost]
        public ApiJsonResult RestUserPwd(TSysUser_IN input)
        {
            var res = _sysUserService.RestUserPwd(input);
            return ApiJsonResult.Convert(res);
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiJsonResult UpdatePwd(TSysUser_IN input)
        {
            var res = _sysUserService.UpdatePwd(input);
            return ApiJsonResult.Convert(res);
        }

        /// <summary>
        /// 获取登录用户信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiJsonResult GetLoginUserInfo()
        {
            var res = _sysUserService.GetLoginUserInfo();
            return ApiJsonResult.Convert(res);
        }

        /// <summary>
        /// 获取登录日志（曲线图）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiJsonResult GetLoginLogs()
        {
            var res = _sysUserService.GetLoginLogs();
            return ApiJsonResult.Convert(res);
        }
    }
}
